const mysql = require("mysql2")

const config = require('./config');

const connection = mysql.createPool({
  host: config.MYSQL_HOST,
  database: config.MYSQL_DATABASE,
  port: config.MYSQL_PORT,
  user: config.MYSQL_USER,
  password: config.MYSQL_PASSWORD
})

connection.getConnection((err, conn) => {
  conn.connect((err) => {
    // 当err为空,说明连接成功
    if (err) {
      console.log("连接失败")
    } else {
      console.log("连接成功")
    }
  })
})

module.exports = connection.promise()